package com.qf.springmvc.redirect;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/test2")
@SessionAttributes("hobby")
public class TestController2 {
    @RequestMapping("/test1")
    public String test1(){
        System.out.println("test2222222222222222222222222221执行了----------------");
        return "forward:test3";
    }
    @RequestMapping("/test3")
    public String test2(HttpServletRequest req, HttpSession session){
        req.setAttribute("name","xiaohuozi");
        session.setAttribute("age","18");
        req.getSession().setAttribute("hobby","吃粑粑");
//        req.getSession().setAttribute("name","xiaohuozi");
//        req.getSession().setAttribute("age","18");
        System.out.println("test222222222222222211111111111111111112执行了----------------");
        return "forward:/success.jsp";
    }
    @RequestMapping("/test4")
    public String test3(Model model){
        model.addAttribute("name","二百五");
        model.addAttribute("age","18");
        model.addAttribute("hobby","吃dumpling");

        return "forward:/success.jsp";
    }
    @RequestMapping("/test5")
    public ModelAndView test5(ModelAndView modelAndView){
        modelAndView.addObject("name","liyao");
        modelAndView.addObject("age","66");
        modelAndView.addObject("hobby","吃dumpling口味的翔");
        modelAndView.setViewName("/success.jsp");

        return modelAndView;
    }
    @RequestMapping("/clear")
    public String hello(SessionStatus status){
        // 移除通过SessionAttributes存入的session
        status.setComplete();
        return "/success.jsp";
    }

}
